<?php

namespace App\Http\Controllers\Api\V1;

use App\Models\Renting;
use App\services\JwtService;
use Illuminate\Http\Request;

class UserController extends BaseController
{
    public function userinfoFun(Request $request){
        $params =$request->all();
        /* //获取token   //转换token 获取id值   封装公共层 方便多次提取
        $token = $request->header('token');
        $id= (new JwtService())->decode($token)['id'];*/

        //控制器不允许出现 数据库更改，控制器只有接参数，调用逻辑层 和 模型层
      /*  $params = $this->validateParams($request->all(),[

            'avatar'=>'required',
            'nickname'=>'required',
            'sex'=>'required',
        ]);*/
        //从数据库更新

        //从中间件中的 request 中 获取
        $res= Renting::find($request->user_id)->update($params);
        $result= Renting::getUserInfoById($request->user_id);
        if ($res){

            return $this->writeJson(0,$result,"数据修改成功");
        }else{

            return $this->writeJson(0,null,"数据修改失败");
        }


    }

    public function getUserInfo(Request $request){

        $res= Renting::find($request->user_id);


        if ($res){

            return $this->writeJson(0,$res,"获取信息成功");
        }else{

            return $this->writeJson(0,null,"获取信息失败");
        }


    }



}
